﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PublSystem.Models;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

namespace PublSystem
{
    public partial class Publications : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int pageId;

            try
            {
                pageId = int.Parse(Request.QueryString["page"]);
            }
            catch
            {
                pageId = 1;
            }

            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString()))
            {
                SqlDataAdapter cmd = new SqlDataAdapter("SELECT * FROM PublicationsInfo.Publications WHERE publicationId < " + pageId * 10 + "AND publicationId > " + (pageId - 1) * 10 + ";", conn);
                conn.Open();
                DataSet ds = new DataSet();
                cmd.Fill(ds);

                publs.DataSource = ds;
                publs.DataBind();
            }

            List<Links> links = new List<Links>();
            for (int i = (pageId >= 6) ? pageId - 5 : 1; i < pageId + 5; i++)
            {
                links.Add(new Links() { PageId = i, Link = "Publications?page=" + i });
            }

            if (!IsPostBack)
            {
                pageNums.DataSource = links;
                pageNums.DataBind();
            }
        }
    }
}